$package('itsm.system');

itsm.system.regiterCodeList=function(){
	this.opt='';
	return {
		//列表
		regiterCodeListGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'registerCode!findRegisterCode.action',
				caption:'激活码列表',
				colNames:['ID','激活码','凭证','用户账号','状态','备注','创建时间','使用时间'],
			 	colModel:[
			 	          {name:'id',align:'center'},
			 	          {name:'code',align:'center'},
			 	          {name:'token',align:'center'},
			 	          {name:'loginName',align:'center'},
			 	          {name:'status',align:'center'},
			 	          {name:'remark',align:'center'},
			 	          {name:'createTime',align:'center'},
			 	          {name:'useTime',align:'center'}
			 	          
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "id"}),
				sortname:'createTime',
				toolbar:[true,"top"],
				sortorder:'desc',
				pager:'#regiterCodeListPager'
				});
				$("#regiterCodeListGrid").jqGrid(params);
				$("#regiterCodeListGrid").navGrid('#regiterCodeListPager',navGridParams);
				//列表操作项
				$("#t_regiterCodeListGrid").css(jqGridTopStyles);
				$("#t_regiterCodeListGrid").html($('#regiterCodeListGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#regiterCodeListGrid","regCenter",10);
		},
		searchRegisterCode:function(){
			var param = $("#regiterCodeList_search_form").serialize();
			$("#regiterCodeListGrid").setGridParam({"postData":param}).trigger("reloadGrid");
		},
		//禁用
		banRegiterCode:function(){
			$.messager.confirm("操作提示", "您确定要执行操作吗？", function (data) {  
	            if (data) {  
	            	var arr = $("#regiterCodeListGrid").jqGrid("getGridParam","selarrrow");
	            	if(arr.length == 0){
	            		$.messager.alert("操作提示","请选择一项");
	            		return;
	            	}
	    			var ids = "";
	    			for(var i = 0 ; i < arr.length ; i ++){
	    				if(i != 0){
	    					ids += "&ids="+arr[i]
	    				}else{
	    					ids += "ids="+arr[i]
	    				}
	    			}
	    			
	    			$.post("registerCode!banRegisterCode.action",ids,function(){
	    				$("#regiterCodeListGrid").trigger("reloadGrid");
	    			});
	            }  
	        });  
		},
		///删除
		deleRegiterCode:function(){
			checkBeforeDeleteGrid('#regiterCodeListGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("registerCode!deleRegisterCodes.action",pp,function(){
					$("#regiterCodeListGrid").trigger("reloadGrid");
				});
			
			});
		},
		//生成
		generate:function(){
			$.post("registerCode!generateRegisterCode.action","num="+$("#num").val()+"&remark="+$("#remark").val(),function(data){
				$("#registerCodeList").html("<tr><td>激活码</td><td>备注</td><td>状态</td><td>创建时间</td></tr>");
				for(var i = 0 ; i < data.length ; i ++){
					$("#registerCodeList").append("<tr><td>"+data[i].code+
							"</td><td>"+data[i].remark+"</td><td>"+
							data[i].status+"</td><td>"+data[i].createTime+"</td></tr>")
				}

				$("#generateCodeWindow").window("open");
				$("#regiterCodeListGrid").trigger("reloadGrid");
			});
		}
		,
		init:function(){
			itsm.system.regiterCodeList.regiterCodeListGrid();
			$("#generateCodeWindow").window({
				title:'注册码',
				width:600,
				height:300,
				shadow:true,
				collapsible:false
			});
		}
	}
	
}();

$(function(){
	itsm.system.regiterCodeList.init();
});